from fastapi import APIRouter, Depends
from typing import List
from datetime import datetime, timedelta
import psutil
import random
# from app.service.CpuMonitor import CpuMonitor
# from app.service.DiskMonitor import DiskMonitor
# from app.service.NetworkMonitor import NetworkMonitor
# from app.service.VmMonitor import VmMonitor

from app.core.shared import cpu_monitor,vm_monitor,network_monitor,disk_monitor
summary_router = APIRouter(prefix="/api/summary", tags=["系统摘要"])


@summary_router.get("/cpu", response_model=dict)
async def get_cpu_summary():
    cpu_entity = cpu_monitor.last_cache
    return {
        "value": f"{cpu_entity.cpu_totoal_percent}%" if cpu_entity else "-",
        "desc": "CPU负载正常" if cpu_entity and cpu_entity.cpu_totoal_percent < 70 else "CPU负载较高" if cpu_entity else "暂无数据"
    }


@summary_router.get("/memory", response_model=dict)
async def get_memory_summary():
    memory_info = vm_monitor.last_cache
    return {
        "value": f"{memory_info.vm_percent}%" if memory_info else "-",
        "desc": "内存使用正常" if memory_info and memory_info.vm_percent < 90 else "内存使用较高" if memory_info else "暂无数据"
    }

@summary_router.get("/disk", response_model=dict)
async def get_disk_summary():
    disk_info = disk_monitor.last_cache
    return {
        "value": f"{disk_info.percent}%" if disk_info else "-",
        "desc": "磁盘空间充足" if disk_info and disk_info.percent < 70 else "磁盘空间紧张" if disk_info else "暂无数据"
    }

@summary_router.get("/network", response_model=dict)
async def get_network_summary():
    network_info = network_monitor.last_cache
    return {
        "value": f"{network_info.speed_kb} kbps" if network_info else "-",
        "desc": "网络流量正常" if network_info and network_info.speed_kb < 30 else "网络流量较高" if network_info else "暂无数据"
    }